﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
namespace AlbonWeb.Manager.StyleManager
{
    public partial class StyleManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["top"] != null)
                {
                    ViewState["limit"] = " where parentID=" + Request["top"].ToString();
                    bindStyle();
                }
            }
        }
        //绑定样式
        protected void bindStyle()
        {
            if (styleName.Text.Trim() != "")
            {
                ViewState["limit"] += " and styleName like '%"+styleName.Text.Trim()+"%'";
            }
            string cmdstr = "select count(*) from StyleView where parentID=" + Request["top"].ToString();
            AspNetPager1.RecordCount = int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).ToString());
            SqlParameter[] parameters = new SqlParameter[]{
                new SqlParameter("@tablename","StyleView"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit",ViewState["limit"].ToString()),
                new SqlParameter("@orderby","sequence asc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "netpager", parameters);   
        }

        //换页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindStyle();
        }
        //查询
        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            ViewState["limit"] = " where parentID=" + Request["top"].ToString();
            bindStyle();
        }
        //删除样式
        protected void imgDelete_Click(object sender, ImageClickEventArgs e)
        {
            BLL.StyleBLL stylebll = new BLL.StyleBLL();
            ImageButton imgDelete = (ImageButton)sender;
            stylebll.DeleteStyle(imgDelete.CommandArgument);
            bindStyle();
        }
    }
}